var t = getApp();

Page({
    data: {
        userId: "",
        total: "",
        coupon: !1,
        vid: "",
        usetInfo: null,
        cvid: ""
    },
    onLoad: function(t) {
        t.vid && (this.setData({
            userId: t.vid
        }), this.getVipUser()), t.cvid && this.setData({
            cvid: t.cvid
        }), t.coupon ? (this.setData({
            coupon: t.coupon
        }), wx.setNavigationBarTitle({
            title: "提货券联名"
        })) : wx.setNavigationBarTitle({
            title: "添加会员"
        }), t.debtId && this.setData({
            debtId: t.debtId
        }), t.credit && this.setData({
            credit: t.credit
        });
    },
    tapId: function() {
        this.getVipUser();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    submitTap: function() {
        this.data.coupon ? this.makeOver() : this.vipApply();
    },
    vipApply: function() {
        var e = t.getNetAddresss("plugin.debt-shop.frontend.debt-member.vipBind");
        t._getNetWork({
            url: e,
            data: {
                vip_uid: this.data.userId,
                debtor_id: this.data.debtId,
                amount: this.data.total
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3,
                    success: function(t) {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3);
                    }
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    makeOver: function() {
        var e = t.getNetAddresss("plugin.debt-shop.frontend.debt-member.exchangeCommonCredit");
        t._getNetWork({
            url: e,
            data: {
                connection_id: this.data.cvid,
                amount: this.data.total
            },
            success: function(t) {
                var e = t.data;
                1 == e.result && wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3,
                    success: function(t) {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3);
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getVipUser: function() {
        var e = this, n = t.getNetAddresss("member.member.memberInfo");
        t._getNetWork({
            url: n,
            data: {
                uid: this.data.userId
            },
            success: function(t) {
                var n = t.data;
                1 == n.result && e.setData({
                    usetInfo: n.data
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});